Hello World

Course- AngularJS >

Here is an example of a simple "Hello World" created with Angulseas which shows the model, view and controlling parts of the Angular JS app:


<!DOCTYPE html>
<html lang="en">
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.min.js"></script>
</head>
<body ng-app="myapp">
<div ng-controller="HelloController" >
    <h2>Hello {{helloTo.title}} !</h2>
</div>
<script>
angular.module("myapp", [])
    .controller("HelloController", function($scope) {
        $scope.helloTo = {};
        $scope.helloTo.title = "World, AngularJS";
    } );
</script>
</body>
</html>

In this example the "view" is this part:


<div ng-controller="HelloController" >
    <h2>Hello {{helloTo.title}} !</h2>
</div>

Notice the NG-controller feature. This feature tells AngularJS which controller to use with this view. Notice {{helloTo.title}} is also part of the AngularJS template system. This tells AngularJS to write the "location" value to HTML at this place called heelotichital.

The "controller" is this part:


<script>
angular.module("myapp", [])
    .controller("HelloController", function($scope) {
        $scope.helloTo = {};
        $scope.helloTo.title = "World, AngularJS";
    });
</script>

This code registers an administrator function called "HelloController" in an angular module called "Myapp". This module will be explained later in this tutorial.

Controller function has the $ realm parameter "model". The controller function adds a Hello Java JavaScript object, and it adds a title field to that object. This model is a Haloute It is a value that the view writes in HTML